package com.cn.crmsystem.controller.businessController;

import com.cn.crmsystem.pojo.Product;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.service.businessService.ProductService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@Api(value = "商品",tags ="商品接口API" )
public class AllProductController {
    @Autowired
    private ProductService productService;

    @RequestMapping(value = "/selectProductAll", method = RequestMethod.POST)
    @ApiOperation(value = "查询所有商品", notes = "业务员管理员操作", httpMethod = "POST", response = ResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "product_name", value = "商品名称", paramType = "query", dataType = "product", required = false),
            @ApiImplicitParam(name = "product_code", value = "商品编码", paramType = "query", dataType = "product", required = false),
            @ApiImplicitParam(name = "product_money", value = "价格", paramType = "query", dataType = "product", required = false),
            @ApiImplicitParam(name = "production_id", value = "production_id", paramType = "query", dataType = "product", required = false)
    })
    public ResultJson selectProductAll(@RequestBody
                                       @ApiParam(name ="map",value ="{product_id 商品id(int)," +
                                               "product_name 商品名称(String)," +
                                               "product_company 商品单位(String)," +
                                               "product_code 商品编码(Strinf)," +
                                               "product_money 商品价格(double)," +
                                               "production_id 商品类型(int)," +
                                               "product_state 是否上架（0：上架；1：不上架）(int)," +
                                               "launch_time 上架时间(date)," +
                                               "product_description 产品描述(String) " +
                                               "}")Map map) {
        return productService.selectProductAll(map);
    }

    @RequestMapping(value = "/selectByIdProduct",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID查询商品接口",notes = "业务员管理员操作",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "商品编号",paramType = "query",dataType = "product",required = false)
    public  ResultJson selectByIdProduct(@ApiParam(name = "product",value = "根据ID查询")Integer id){
        return productService.selectByIdProduct(id);
    }

    @RequestMapping(value = "/addProduct",method = RequestMethod.POST)
    @ApiOperation(value = "新增商品接口",notes = "管理员新增",httpMethod = "POST",response = ResultJson.class)

    public  ResultJson addProduct(@RequestBody @ApiParam(name = "product",value = "新增商品")Product product){
        return  productService.addProduct(product);
    }

    @RequestMapping(value = "/updateByIdProduct",method = RequestMethod.POST)
    @ApiOperation(value = "根据ID修改商品",notes = "管理员修改",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "商品编号",required = false,dataType = "product",paramType = "query")
    public ResultJson updateByIdProduct(@ApiParam(name = "product",value = "修改商品")Integer id){
        return  productService.updateByIdProduct(id);
    }
    @RequestMapping(value = "/deleteByIdProduct",method = RequestMethod.POST)
    @ApiOperation(value ="根据ID删除商品接口",notes = "管理员修改",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "活动编号",required = false,dataType = "product",paramType = "query")
    public ResultJson deleteByIdProduct(@ApiParam(name = "product",value = "删除商品")Integer id){
        return  productService.deleteByIdProduct(id);
    }
}
